public class Queue <Item>{
    private class Node{
        Node next;
        Item val;
        private Node(Item val){
            this.val = val;
        }
    }
    private Node head;
    private Node last;
    private int N;
    public boolean isEmpty(){
        return N==0;
    }
    public int size(){
        return N;
    }
    public void enqueue(Item item){
        //向表尾添加元素
        Node oldlast= last;
        last = new Node(item);
        if(isEmpty()){
            head = last;
        }else{
            oldlast.next = last;
        }
        N++;
    }
    public Item dequeue(){
        //从表头删除元素
        if(isEmpty()){
            return null;
        }else{
            Item tem = head.val;
            head = head.next;
            if(isEmpty()){
                last = null;
            }
            N--;
            return tem;
        }
    }
}
